/***********************************************************************************
Copy right:     Coffee Tech.
Author:         jiaoyue
Date:           2019.8.1
Description:    文件测试
***********************************************************************************/

#include <file_opt.h>

/**
 * 根据文件大小，精准分配缓冲区并读取文件的内容
*/
int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("usage:%s <file>\n", argv[0]);
        return -1;
    }

    //先判断文件是否存在
    if(!fileopt_exist(argv[1]))
    {
        printf("file %s not exit\n", argv[1]);
        return -1;
    }

    long size = fileopt_getsize(argv[1]);
    char *buf = (char *)malloc(size);

    int ret = fileopt_readall(argv[1], buf);
    if(ret < 0)
    {
        printf("read err\n");
        return -1;
    }

    printf("read data = \n%s\n", buf);

    free(buf);

    return 0;
}
